package io.nads.controller;

import io.nads.context.BaseContext;
import io.nads.dto.Result;
import io.nads.entity.ChatSession;
import io.nads.service.ChatSessionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: shzhu
 * @Date: 2025/9/26 23:20
 * @Description:
 */
// todo 这些接口还没有测试，因为我目前不知道登录那边是如何操作的，如何才能将userId保存到BaseContext中
@RestController
@RequestMapping("/session")
@Tag(name = "会话相关接口", description = "提供会话的增删改查")
public class ChatSessionController {
    @Autowired
    private ChatSessionService chatSessionService;


    /**
     * Restful 风格的创建新会话
     */

    @Operation(summary = "创建一个新会话", description = "创建一个新会话")
    @PostMapping
    Result createSession(@Parameter(description = "会话名称", example = "一个幽默的鲁迅") @RequestParam String topic) {
        chatSessionService.createNewSession(topic);
        return Result.ok();
    }


    @Operation(summary = "更改一个会话", description = "更改一个新会话")
    @PutMapping
    public Result updateSession(@Parameter(description = "ChatSession对象") @RequestBody ChatSession chatSession) {
        chatSessionService.updateSession(chatSession);
        return Result.ok();
    }

    @Operation(summary = "删除一个会话", description = "删除一个新会话")
    @DeleteMapping
    public Result deleteSession() {
        chatSessionService.deleteSession(BaseContext.getCurrentId());
        return Result.ok();
    }

    @Operation(summary = "查询所有会话", description = "查询所有会话")
    @GetMapping
    public Result selectAllSession() {
        List<ChatSession> chatSessions = chatSessionService.selectAllSession();
        return Result.ok(chatSessions);
    }


}
